package com.ht.medicaltreatment.activity.haocai2

import android.content.Intent
import android.os.Bundle
import android.util.TypedValue
import android.view.Gravity
import android.widget.TableLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.fragment.haocai2.ConsumableRecordFragment
import kotlinx.android.synthetic.main.activity_consumable_record_layout.tabLayout
import kotlinx.android.synthetic.main.activity_consumable_record_layout.tvAdd
import kotlinx.android.synthetic.main.activity_consumable_record_layout.viewPager

//耗材申请记录
class ConsumableRecordActivity : BaseActivity(){

    private val tabTitles = arrayListOf("全部","同意","待审核","拒绝")
    private val fragments = arrayListOf(ConsumableRecordFragment(),ConsumableRecordFragment(),ConsumableRecordFragment(),ConsumableRecordFragment())

    private var id = 0
    override fun getLayoutId() = R.layout.activity_consumable_record_layout

    override fun init() {
        setTitle("申请列表")
        id = intent.getIntExtra("id",0)
        viewPager.adapter = object : FragmentStateAdapter(this){
            override fun getItemCount() = tabTitles.size
            override fun createFragment(position: Int): Fragment {
                val bundle = Bundle()
                bundle.putInt("position",position)
                bundle.putInt("id",id)
                fragments[position].arguments = bundle
                return fragments[position]
            }
        }
        val tableLayout = TabLayoutMediator(tabLayout,viewPager,object : TabLayoutMediator.TabConfigurationStrategy{
            override fun onConfigureTab(tab: TabLayout.Tab, position: Int) {
                val textView = TextView(this@ConsumableRecordActivity)
                val params = TableLayout.LayoutParams()
                params.width = TableLayout.LayoutParams.WRAP_CONTENT
                params.height = TableLayout.LayoutParams.WRAP_CONTENT
                textView.layoutParams = params
                textView.gravity = Gravity.CENTER
                textView.setText(tabTitles[position])
                textView.setTextColor(getColor(R.color.black))
                textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,15f)
                tab.setCustomView(textView)
            }
        })
        tableLayout.attach()

        //申请耗材
        tvAdd.setOnClickListener {
            val intent = Intent(this,ApplyConsumableActivity::class.java)
            intent.putExtra("id",id)
            startActivity(intent)
        }
    }

}